package com.zl.zlproject.ui.me.fragment;


import android.content.Intent;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.zl.zlproject.R;
import com.zl.zlproject.base.application.MyApplication;
import com.zl.zlproject.base.fragment.BaseMvpFragment;
import com.zl.zlproject.base.presenter.BaseContract;
import com.zl.zlproject.ui.me.activity.AboutAuthorActivity;
import com.zl.zlproject.utils.GildeCircleTransform;
import com.zl.zlproject.widget.NormalItemView;
import com.zl.zlproject.widget.WaveeView;
import com.zl.zlproject.widget.ZlLayoutManager;

import butterknife.BindView;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by 郑磊 on 2018/5/27.
 */

public class MeFragment extends BaseMvpFragment {

    @BindView(R.id.item_about_author)
    NormalItemView mItemView;

    @BindView(R.id.iv_icon)
    ImageView mIvIcon;

    @BindView(R.id.wave_view)
    WaveeView mWaveeView;
    @BindView(R.id.ll_error)
    LinearLayout mLlError;
    @BindView(R.id.layout_manager)
    ZlLayoutManager mLayoutManager;
    @BindView(R.id.refresh_layout)
    SmartRefreshLayout mRefreshLayout;
    @BindView(R.id.fl_head)
    FrameLayout mFlHead;
    @BindView(R.id.tv_user_name)
    TextView mTvUserName;
    @BindView(R.id.tv_nick_name)
    TextView mTvNickName;
    Unbinder unbinder;


    public void onRefresh(@NonNull RefreshLayout refreshLayout) {

    }

    @Override
    protected void initView() {
        super.initView();
        mFlHead.setBackgroundResource(MyApplication.appColor);
        mRefreshLayout.setPrimaryColorsId(MyApplication.appColor, android.R.color.white);
        final FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(-2, -2);
        layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER;
        mWaveeView.setOnWaveAnimationListener(new WaveeView.OnWaveAnimationListener() {
            @Override
            public void onWaveAnimation(float y) {
                layoutParams.setMargins(0, 0, 0, (int) y + 20);
                mIvIcon.setLayoutParams(layoutParams);
            }
        });

//        mRefreshLayout.autoRefresh();
        mRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                mRefreshLayout.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mRefreshLayout.finishRefresh();
                    }
                }, 2000L);
            }
        });


        Glide.with(this).load(R.mipmap.default_user_icon)
                .transform(new GildeCircleTransform(getContext()))
                .dontAnimate()
                .into(mIvIcon);
        mRefreshLayout.setEnableLoadMore(false);

    }

    @Override
    protected int getContentLayoutId() {
        return R.layout.fragment_me;
    }


//    @OnClick(R.id.item_about_author)
//    public void onClick() {
//        startActivity(new Intent(getContext(), AboutAuthorActivity.class));
//    }

    @Override
    protected BaseContract.Presenter initPresenter() {
        return null;
    }




    @OnClick({R.id.iv_setting, R.id.iv_icon, R.id.item_about_author})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_setting:

                break;
            case R.id.iv_icon:

                break;
            case R.id.item_about_author:
                startActivity(new Intent(getContext(), AboutAuthorActivity.class));
                break;
        }
    }
}
